# -*- coding: utf-8 -*-

__author__ = 'bitfeng'

import re
import hashlib
import datetime
import random

# 因文件名中包含通配符易导致系统问题，此函数将文件名中包含的通配符特换为_
def renameFile(name):
    return re.sub(u'[\s,\*,\?,#,\|,;,~,$,!,/,>,>>,\',\",`,\(,\),\[,\],\{,\},:,\.,-]', '_', name)


# 文件路径拼接
def joinpath(paths):
    if '' in paths:
        paths.remove('')
    return '/'+'/'.join([path.strip('/') for path in paths])


# MD加密
def MD5(string):
    if isinstance(string, str):
        return hashlib.md5(string).hexdigest()
    elif isinstance(string, unicode):
        return hashlib.md5(string.encode('utf8')).hexdigest()
    else:
        return


# 随机文件名
def random_filename():
    return renameFile(str(datetime.datetime.now())+'_'+str(random.randint(10000, 99999)))
